#ifndef MESSAGEDEF_H_
#define MESSAGEDEF_H_

#include <iostream>
#include <string.h>
#include <stdlib.h>
#include <stdbool.h>
#include <arpa/inet.h>
#include <netinet/in.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>


using namespace std;

#define CONFIG_FILE 		"ConfigFile.txt"
#define ROUTER_PORT_FILE 	"RouterInfo.txt"

#define MESSAGE_LENGTH 			1024
#define DATA_MESSAGE_MAX		50

#define HELLO_PERIOD			3000000
#define MAX_HELLO_DROP			3

#define RESEND_PERIOD			5000000

#define MSG_HELLO 				1
#define MSG_HELLO_ACK			10
#define MSG_UPDATE 				2
#define MSG_UPDATE_ACK 			3
#define MSG_WITHDRAW 			4
#define MSG_WITHDRAW_ACK 		5
#define MSG_DATA 				6
#define MSG_DATA_ACK 			7
#define MSG_GATEWAY_INFO 		8
#define MSG_GATEWAY_INFO_ACK	9


// To store internal node info
typedef struct NodeInfo
{
	NodeInfo()
	{
		nNodeID			= 0;
		strIP			= "";
		nPort			= 0;
		Clientsockfd	= 0;
		nNeighbCount	= 0;
		bGateway		= false;
		nGatewayID		= -1;
	}
	int nNodeID;
	string strIP;
	int nPort;
	int Clientsockfd;
	int nNeighbCount;
	bool bGateway;
	int nGatewayID;

}NODE_INFO;


// To store Neighbour info
typedef struct NeighInfo
{
	NeighInfo()
	{
		nNodeID 		= 0;
		//struct sockaddr_in NeighSockAddr;
		strIP 			= "";
		nPort 			= 0;
		bGateway 		= false;
		bSendHello 		= false;
		bAckHello 		= false;
		nHelloCount		= 0;
		bAlive 			= false;
		nUpdateSendCount= 0;
		//int nUpdateAckCount;
		nLastDataSeqNo	= 0;

	}
	int nNodeID;
	struct sockaddr_in NeighSockAddr;
	string strIP;
	int nPort;
	bool bGateway;
	bool bSendHello;
	bool bAckHello;
	int nHelloCount;
	bool bAlive;
	int nUpdateSendCount;
	//int nUpdateAckCount;
	int nLastDataSeqNo;
}NEIGBOUR_INFO;


typedef struct Message
{
	Message()
	{
		nHeader				= 0 ;
		nSeqNo				= 0 ;
		nSourceID			= 0 ;
		nDestinationID		= 0 ;
		nMessageType		= 0 ;
		nMessageSize		= 0 ;
		Data				= NULL;
	}
	unsigned int nHeader;
	unsigned int nSeqNo;
	unsigned short nSourceID;
	unsigned short nDestinationID;
	unsigned short nMessageType;
	unsigned short nMessageSize;
	char* Data;
}MESSAGE;
#define MESSAGE_HEADER_LEN (sizeof(Message)-sizeof(char*))

typedef struct DataStore
{

	DataStore()
	{
		//struct sockaddr_in ClientInfo;
		nSeqNo			= 0;
		nMessageType	= 0;
		nNextHop		= 0;
		nMessageSize	= 0;
		//pEncodedMessage	= NULL;
		memset(strEncodedMessage, '0', sizeof(strEncodedMessage));
	}

	struct sockaddr_in ClientInfo;	//NeighbourInfo
	unsigned int nSeqNo;
	unsigned short nMessageType;	//If data message, seq number need not be updated
	unsigned short nMessageSize;
	unsigned short nNextHop;
	//char* pEncodedMessage;
	char strEncodedMessage[MESSAGE_LENGTH];
}DATASTORE;

typedef struct RouteTable
{
	RouteTable()
	{
		nFinalDest		= 0;
		nNextHop		= 0;
		for(int i = 0; i<10; i++)
			arrPath[i]	= 0;
		nHopCount		= 0;
		bActivePath		= false;
		bPathFromGateWay= false;
	}

	int nFinalDest;
	int nNextHop;
	char arrPath[10];
	int nHopCount;
	bool bActivePath;
	bool bPathFromGateWay;
}ROUTE_TABLE;


#endif
